package com.sky.mapper;

import com.sky.dto.GoodsSalesDTO;
import com.sky.entity.Orders;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;

import java.time.LocalDate;
import java.time.LocalDateTime;
import java.util.List;
import java.util.Map;

@Mapper
public interface OrdersMapper {
    /**
     * 插入订单
     * @param orders
     */
    void insert(Orders orders);
    /**
     * 根据订单号和用户id查询订单
     * @param orderNumber
     * @param userId
     */
    @Select("select * from orders where number = #{orderNumber} and user_id= #{userId}")
    Orders getByNumberAndUserId(String orderNumber, Long userId);

    /**
     * 修改订单信息
     * @param orders
     */
    void update(Orders orders);

@Select("select id, number, status, user_id, address_book_id, order_time, checkout_time, pay_method, pay_status, amount, remark, phone, address, user_name, consignee, cancel_reason, rejection_reason, cancel_time, estimated_delivery_time, delivery_status, delivery_time, pack_amount, tableware_number, tableware_status from orders where status=#{pendingPayment} and order_time=#{localDateTime}")
List<Orders> getByStatusAndOrdertimeLT(Integer pendingPayment, LocalDateTime localDateTime);

    /**
     * 催单
     * @param id
     * @return
     */
    @Select("select id, number, status, user_id, address_book_id, order_time, checkout_time, pay_method, pay_status, amount, remark, phone, address, user_name, consignee, cancel_reason, rejection_reason, cancel_time, estimated_delivery_time, delivery_status, delivery_time, pack_amount, tableware_number, tableware_status from orders where id = #{id}")
    Orders getById(Integer id);

    /**
     * 根据map条件查询当天营业额
     * @param map
     * @return
     */

    Double getByMap(Map map);

    /**
     * 根据条件查询用户数量
     * @param map
     * @return
     */
    Integer userCount(Map map);

    /**
     * 根据条件查询订单数量
     * @param map
     * @return
     */
    Integer ordersStatistics(Map map);

    /**
     * 根据条件获得选定时间内的销量前十
     * @param begin
     * @param end
     * @return
     */
    List<GoodsSalesDTO> getGoodsTop10(LocalDate begin, LocalDate end);
}
